<template>
    <div class="app-container">
        <el-card shadow="never">
            <!-- 条件查询 -->
            <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="120px" @keyup.enter.native="submitSearch" @submit.native.prevent>
                <el-row>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="订单:" prop="name.value">
                            <el-input v-model="queryParams.name.value" placeholder="请输入订单号" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="支付状态:" prop="financial_status.value">
                            <el-select v-model="queryParams.financial_status.value" placeholder="请选择" clearable>
                                    <el-option label="请选择" :value="0" />
                                    <el-option label="已支付" :value="1" />
                                    <el-option label="部分支付" :value="2" />
                                    <el-option label="部分退款" :value="3" />
                                    <el-option label="退款" :value="4" />
                                </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="发货状态:" prop="fulfillment_status.value">
                            <el-select v-model="queryParams.fulfillment_status.value" placeholder="请选择" clearable>
                                    <el-option label="请选择" :value="0" />
                                    <el-option label="已发货" :value="1" />
                                    <el-option label="部分发货" :value="2" />
                                    <el-option label="重新补货" :value="3" />
                                    <el-option label="未发货" :value="4" />
                                </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="标签:" prop="tags.value">
                            <el-input v-model="queryParams.tags.value" placeholder="请输入标签" clearable />
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :md="6" :sm="12">
                        <el-form-item label="店铺:" prop="site_id.value">
                            <SelectPage v-model="queryParams.site_id.value" :url="'/admin/site/selectPage'" show_field="site_name" placeholder="请选择新店铺" query_field="site_name" :multiple="false" />
                        </el-form-item>
                    </el-col> -->
                    <el-col :md="12" :sm="12">
                        <el-form-item label="出单时间:" prop="created_at.value">
                            <el-date-picker
                                v-model="queryParams.created_at.value"
                                type="datetimerange"
                                range-separator="至"
                                start-placeholder="开始"
                                end-placeholder="结束"
                                align="right"
                                value-format="yyyy-MM-dd HH:mm:ss"
                            >
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :md="12" :sm="12">
                        <el-form-item class="ele-text-right" label-width="50px">
                            <el-button type="primary" size="mini" @click="submitSearch" icon="el-icon-search" class="ele-btn-icon">搜索 </el-button>
                            <el-button @click="resetQuery" size="mini" icon="el-icon-refresh">重置</el-button>

                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <el-upload
                        class="upload-demo"
                        ref="upload"
                        :action="api.upload"
                        :on-preview="handlePreview"
                        :on-remove="handleRemove"
                        :on-success="handleUploadSuccess"
                        :on-error="handleUploadError"
                        :file-list="fileList"
                        :auto-upload="false">
                        <!-- <el-button slot="trigger" size="small" type="primary">选择文件</el-button> -->
                        <!-- <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传运费</el-button> -->
                        <!-- <el-button class="btn-mar" size="small" type="warning" icon="el-icon-edit">
                            <router-link
                                    :to="{
                                        path: '/storage/system/feditionordertransfer.xls',
                                    }"
                                >
                                下载运费模板
                            </router-link>
                        </el-button> -->
                    </el-upload>
                </el-col>
                <el-col :span="1.5">
                    <!-- <el-button type="warning" plain icon="el-icon-download" size="mini" v-loading="exportLoading" @click="handleExport" v-hasPermi="api.export">导出</el-button> -->
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="initIndex" :columns="columns" printId="#quickadmin"></right-toolbar>
            </el-row>

            <!-- 列表 -->
            <qa-table
                :source="tableData"
                :columns="columns"
                :selection="true"
                :loading="loading"
                @sortChange="sortChange"
                @statusChange="statusChange"
                @selectionChange="selectionChange"
                id="quickadmin"
            >
                <template v-slot:action>
                    <el-table-column label="操作" width="" align="left">
                        <template slot-scope="scope">
                            <el-button class="btn-mar" size="mini" type="primary" @click="handleEdit(scope.row)" v-hasPermi="api.edit">手动修正</el-button>
                            <!-- <el-button class="btn-mar" size="mini" type="info" icon="el-icon-tickets" @click="handleDetail(scope.row)" v-hasPermi="api.find">详情</el-button> -->
                            <!-- <el-button class="btn-mar" size="mini" type="danger" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="api.delete">删除</el-button> -->
                        </template>
                    </el-table-column>
                </template>

            </qa-table>

            <!-- 分页 -->
            <pagination :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="initIndex" />
        </el-card>

        <!-- 编辑弹窗 -->
        <el-dialog :title="!disabled ? '编辑' : '详情'" :visible="editOpen"  :before-close="beforeClose" destroy-on-close>
            <EditForm ref="editForm" :findFormData="findFormData"  :disabled="disabled" @submitForm="submitForm" :editFormParams="editFormParams" @editFormCancel="beforeClose" />
        </el-dialog>

    </div>
</template>

<script>
import { curdMixin } from '@/mixins/curdMixin'
import EditForm from './EditFormCom'
export default {
    name: 'Curd',
    mixins: [curdMixin],
    components: { EditForm },
    
    data() {
        return {
            fileList: [],
            us_time: 0,
            value: new Date(),
            // table结构
            columns: [
                {
                    visible: true,
                    label: '店铺',
                    prop: 'site_name',
                },
                {
                    visible: true,
                    label: '订单号',
                    prop: 'name',
                },
                {
                    visible: true,
                    label: '出单时间',
                    prop: 'created_at',
                },
                {
                    visible: true,
                    label: '金额',
                    prop: 'total_price',
                },
                {
                    visible: true,
                    label: '支付状态',
                    prop: 'financial_status',
                },
                {
                    visible: true,
                    label: '发货状态',
                    prop: 'fulfillment_status',
                },
                {
                    visible: true,
                    label: '支付方式',
                    prop: 'gateway',
                },
                {
                    visible: true,
                    label: '邮箱',
                    prop: 'email',
                },
                {
                    visible: true,
                    label: '物流单',
                    prop: 'tracking_number',
                },
                {
                    visible: true,
                    label: '标签',
                    prop: 'tags',
                },

            ],
            // 接口地址
            api: {
                index: `/admin/ordercorrect/index`,
                find: `/admin/ordercorrect/find`,
                add: `/admin/ordercorrect/add`,
                edit: `/admin/ordercorrect/edit`,
                delete: `/admin/ordercorrect/delete`,
                export: `/admin/ordercorrect/export`,
                upload: `https://api.fan-zhou.com/admin/ordercorrect/uploads`,
                status: `/admin/ordercorrect/status`
            },
            editFormParams: {
            },
            pageInfo: {
                sort: 'id',
            },
            primaryKey: 'id',
            // 搜索表单是否展开
            searchExpand: false,
              //是否展示搜索
            showSearch: true,
            // 查询参数
            queryParams: {
                name: { value:undefined, op: '%like%'},
                tags: { value:undefined, op: '%like%'},
                site_id: { value:undefined, op: '='},
                created_at: { value: [], op: 'range' },
                financial_status: { value:undefined, op: '='},
                fulfillment_status: { value:undefined, op: '='},
            },

        }
    },
    created () {
        this.initIndex()
        this.now()
    },
    watch: {
        
    },
    methods: {
        day_change() {
            
            console.log('test',this.value);
            console.log('data.isSelected',this.data.isSelected);
        },
        now() {
            this.us_time = new Date().getTime() - 15 * 3600 * 1000;
            setInterval(() => {
                this.us_time = new Date().getTime() - 15 * 3600 * 1000;
            }, 1000)
        },
        // 案列：当前组件格式化方法
        testFormatter(prop) {
            return prop
        },
        
        submitUpload() {
            this.loading = true
            this.$refs.upload.submit();
        },
        handleRemove(file, fileList) {
            console.log(file, fileList);
        },
        handlePreview(file) {
            console.log(file);
        },
        
        // 上传成功回调
        handleUploadSuccess(res) {
            this.loading = false
            if (res.code == 1) {
                this.$message.success('上传成功');
                this.initIndex();
            } else {
                this.$message({
                    type: 'error',
                    message: '上传失败'+res.msg,
                })
            }
        },
        // 上传失败
        handleUploadError() {
            this.$message({
                type: 'error',
                message: '上传失败',
            })
        },
    }
}
</script>
<style lang="scss">
.btn-mar {
    margin: 5px !important;
}
.is-selected {
    color: #1989FA;
}
</style>